﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WeChatTool
{
	public class FileChangeInformation
	{
		public FileChangeInformation(string id, FileChangeType rename, string fullPath, string name)
		{
			Id = id;
			ChangeType = rename;
			OldFullPath = fullPath;
			FullPath = fullPath;
			OldName = name;
			Name = name;
		}

		public FileChangeInformation(string id, FileChangeType rename, string oldFullPath, string fullPath, string oldName, string name)
		{
			Id = id;
			ChangeType = rename;
			OldFullPath = oldFullPath;
			FullPath = fullPath;
			OldName = oldName;
			Name = name;
		}


		public FileChangeType ChangeType { get; internal set; }
		public string Id { get; set; }
		public string OldFullPath { get; set; }
		public string FullPath { get; set; }
		public string OldName { get; set; }
		public string Name { get; set; }

		public override string ToString()
		{
			return $"{ChangeType.GetDescription()}:{Name}";
		}
	}

	public enum FileChangeType
	{
		[Description("未知")]
		Unknow,
		[Description("新目录")]
		NewFolder,
		[Description("新文件")]
		NewFile,
		[Description("修改")]
		Change,
		[Description("删除")]
		Delete,
		[Description("重命名")]
		Rename,
		All

	}

	static class EnumExtensions
	{
		public static string GetDescription(this Enum val)
		{
			var field = val.GetType().GetField(val.ToString());
			var customAttribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute));
			if (customAttribute == null) { return val.ToString(); }
			else { return ((DescriptionAttribute)customAttribute).Description; }
		}
	}
}
